IF OBJECT_ID('fGetSegmentName') IS NOT NULL 
BEGIN 
    DROP FUNCTION fGetSegmentName
    IF OBJECT_ID('fGetSegmentName') IS NOT NULL
        PRINT '<<< FAILED DROPPING FUNCTION fGetSegmentName >>>'
    ELSE 
        PRINT '<<< DROPPED FUNCTION fGetSegmentName >>>'
END
GO
CREATE FUNCTION dbo.fGetSegmentName
(
    @SegmentId   int = NULL
)
RETURNS varchar(255)
AS
BEGIN
    DECLARE
        @SegmentName varchar(255)

    SELECT @SegmentName = SegmentName FROM Segment WHERE SegmentId = @SegmentId

RETURN @SegmentName
END
GO
GRANT EXECUTE ON fGetSegmentName TO public
GO
IF OBJECT_ID('fGetSegmentName') IS NOT NULL 
    PRINT '<<< CREATED FUNCTION fGetSegmentName >>>' 
ELSE 
    PRINT '<<< FAILED CREATING FUNCTION fGetSegmentName >>>' 
GO
